{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Introduction to atomman: Point defect generation\n",
    "\n",
    "__Lucas M. Hale__, [lucas.hale@nist.gov](mailto:lucas.hale@nist.gov?Subject=ipr-demo), _Materials Science and Engineering Division, NIST_.\n",
    "    \n",
    "[Disclaimers](http://www.nist.gov/public_affairs/disclaimer.cfm)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Introduction<a id='section1'></a>\n",
    "\n",
    "This Notebook provides an introduction to tools in atomman for generating point defects."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Library Imports**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "atomman version = 1.4.0\n",
      "Notebook executed on 2021-08-05\n"
     ]
    }
   ],
   "source": [
    "# Standard libraries\n",
    "import datetime\n",
    "\n",
    "# http://www.numpy.org/\n",
    "import numpy as np             \n",
    "\n",
    "# https://github.com/usnistgov/atomman\n",
    "import atomman as am            \n",
    "import atomman.unitconvert as uc\n",
    "\n",
    "# Show atomman version\n",
    "print('atomman version =', am.__version__)\n",
    "\n",
    "# Show date of Notebook execution\n",
    "print('Notebook executed on', datetime.date.today())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Define 2x2x2 CsCl supercell for testing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "avect =  [ 8.220,  0.000,  0.000]\n",
      "bvect =  [ 0.000,  8.220,  0.000]\n",
      "cvect =  [ 0.000,  0.000,  8.220]\n",
      "origin = [ 0.000,  0.000,  0.000]\n",
      "natoms = 16\n",
      "natypes = 2\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>atype</th>\n",
       "      <th>pos[0]</th>\n",
       "      <th>pos[1]</th>\n",
       "      <th>pos[2]</th>\n",
       "      <th>charge</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    atype  pos[0]  pos[1]  pos[2]  charge\n",
       "0       1   0.000   0.000   0.000    -1.0\n",
       "1       2   2.055   2.055   2.055     1.0\n",
       "2       1   4.110   0.000   0.000    -1.0\n",
       "3       2   6.165   2.055   2.055     1.0\n",
       "4       1   0.000   4.110   0.000    -1.0\n",
       "5       2   2.055   6.165   2.055     1.0\n",
       "6       1   4.110   4.110   0.000    -1.0\n",
       "7       2   6.165   6.165   2.055     1.0\n",
       "8       1   0.000   0.000   4.110    -1.0\n",
       "9       2   2.055   2.055   6.165     1.0\n",
       "10      1   4.110   0.000   4.110    -1.0\n",
       "11      2   6.165   2.055   6.165     1.0\n",
       "12      1   0.000   4.110   4.110    -1.0\n",
       "13      2   2.055   6.165   6.165     1.0\n",
       "14      1   4.110   4.110   4.110    -1.0\n",
       "15      2   6.165   6.165   6.165     1.0"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "atoms = am.Atoms(atype=[1,2], pos=[[0.0, 0.0, 0.0],[0.5, 0.5, 0.5]], charge=[-1.0, 1.0])\n",
    "alat = uc.set_in_units(4.11, 'angstrom')\n",
    "box = am.Box(a=alat, b=alat, c=alat)\n",
    "ucell = am.System(atoms=atoms, box=box, scale=True)\n",
    "system = ucell.supersize(2,2,2)\n",
    "\n",
    "# Print system information\n",
    "print(system.box)\n",
    "print('natoms =', system.natoms)\n",
    "print('natypes =', system.natypes)\n",
    "system.atoms_df()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. atomman.defect.vacancy()<a id='section2'></a>\n",
    "\n",
    "Generates a new system by adding a vacancy point defect.\n",
    "\n",
    "1. Removes the indicated atom from the system\n",
    "2. Adds per-atom property old_id if it doesn't exist corresponding to the atom ids in the original system.\n",
    "\n",
    "Parameters\n",
    "\n",
    "- **system** (*atomman.System*) The base System to add the defect to.\n",
    "- **pos** (*array-like object, optional*) Position of the atom to be removed.  Either pos or ptd_id must be given.\n",
    "- **ptd_id** (*int, optional*) Id of the atom to be removed.  Either pos or ptd_id must be given.\n",
    "- **scale** (*bool, optional*) Indicates if pos is Cartesian (False) or box-relative (True). Default value is False.\n",
    "- **atol** (*float, optional*) Absolute tolerance for position-based searching. Default value is 1e-3 angstroms.\n",
    "\n",
    "Returns\n",
    "\n",
    "- (*atomman.System*) A new system with the vacancy added."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "avect =  [ 8.220,  0.000,  0.000]\n",
      "bvect =  [ 0.000,  8.220,  0.000]\n",
      "cvect =  [ 0.000,  0.000,  8.220]\n",
      "origin = [ 0.000,  0.000,  0.000]\n",
      "natoms = 14\n",
      "natypes = 2\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>atype</th>\n",
       "      <th>pos[0]</th>\n",
       "      <th>pos[1]</th>\n",
       "      <th>pos[2]</th>\n",
       "      <th>charge</th>\n",
       "      <th>old_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    atype  pos[0]  pos[1]  pos[2]  charge  old_id\n",
       "0       1   0.000   0.000   0.000    -1.0       0\n",
       "1       2   2.055   2.055   2.055     1.0       1\n",
       "2       1   4.110   0.000   0.000    -1.0       2\n",
       "3       2   6.165   2.055   2.055     1.0       3\n",
       "4       1   0.000   4.110   0.000    -1.0       4\n",
       "5       1   4.110   4.110   0.000    -1.0       6\n",
       "6       2   6.165   6.165   2.055     1.0       7\n",
       "7       1   0.000   0.000   4.110    -1.0       8\n",
       "8       2   2.055   2.055   6.165     1.0       9\n",
       "9       1   4.110   0.000   4.110    -1.0      10\n",
       "10      2   6.165   2.055   6.165     1.0      11\n",
       "11      2   2.055   6.165   6.165     1.0      13\n",
       "12      1   4.110   4.110   4.110    -1.0      14\n",
       "13      2   6.165   6.165   6.165     1.0      15"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Add a vacancy by deleting atom 5\n",
    "d_system = am.defect.vacancy(system, ptd_id=5)\n",
    "\n",
    "# Add a second vacancy by deleting atom at position [0.00, 4.110, 4.110]\n",
    "d_system = am.defect.vacancy(d_system, pos=[0.00, 4.11, 4.11])\n",
    "\n",
    "# Print system information\n",
    "print(d_system.box)\n",
    "print('natoms =', d_system.natoms)\n",
    "print('natypes =', d_system.natypes)\n",
    "d_system.atoms_df()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. atomman.defect.interstitial()<a id='section3'></a>\n",
    "\n",
    "Generates a new system by adding a vacancy point defect.\n",
    "    \n",
    "1. Adds a new atom to the end of the Atoms list.\n",
    "2. Adds per-atom property old_id if it doesn't exist corresponding to the atom ids in the original system.\n",
    "3. Sets any of the new atom's per-atom properties to values given as kwargs.  Any undefined properties are given zero values except atype, which is set to 1.\n",
    "    \n",
    "Parameters\n",
    "\n",
    "- **system** (*atomman.System*) The base System to add the defect to.\n",
    "- **pos** (*array-like object*) Position of the atom being added.\n",
    "- **scale** (*bool, optional*) Indicates if pos is Cartesian (False) or box-relative (True).  Default value is False.\n",
    "- **atol** (*float, optional*) Absolute tolerance for position-based searching. Default value is 1e-3 angstroms.\n",
    "- **\\*\\*kwargs** (*any, optional*)  Keyword arguments corresponding to per-atom property values for the new atom.  By default, atype==1 and all other properties are set to be all zeros for the property's shape.\n",
    "    \n",
    "Returns\n",
    "\n",
    "- (*atomman.System*) A new system with the interstitial added."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "avect =  [ 8.220,  0.000,  0.000]\n",
      "bvect =  [ 0.000,  8.220,  0.000]\n",
      "cvect =  [ 0.000,  0.000,  8.220]\n",
      "origin = [ 0.000,  0.000,  0.000]\n",
      "natoms = 18\n",
      "natypes = 2\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>atype</th>\n",
       "      <th>pos[0]</th>\n",
       "      <th>pos[1]</th>\n",
       "      <th>pos[2]</th>\n",
       "      <th>charge</th>\n",
       "      <th>old_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>1</td>\n",
       "      <td>1.515</td>\n",
       "      <td>1.515</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>17</td>\n",
       "      <td>2</td>\n",
       "      <td>1.515</td>\n",
       "      <td>4.545</td>\n",
       "      <td>0.000</td>\n",
       "      <td>1.0</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    atype  pos[0]  pos[1]  pos[2]  charge  old_id\n",
       "0       1   0.000   0.000   0.000    -1.0       0\n",
       "1       2   2.055   2.055   2.055     1.0       1\n",
       "2       1   4.110   0.000   0.000    -1.0       2\n",
       "3       2   6.165   2.055   2.055     1.0       3\n",
       "4       1   0.000   4.110   0.000    -1.0       4\n",
       "5       2   2.055   6.165   2.055     1.0       5\n",
       "6       1   4.110   4.110   0.000    -1.0       6\n",
       "7       2   6.165   6.165   2.055     1.0       7\n",
       "8       1   0.000   0.000   4.110    -1.0       8\n",
       "9       2   2.055   2.055   6.165     1.0       9\n",
       "10      1   4.110   0.000   4.110    -1.0      10\n",
       "11      2   6.165   2.055   6.165     1.0      11\n",
       "12      1   0.000   4.110   4.110    -1.0      12\n",
       "13      2   2.055   6.165   6.165     1.0      13\n",
       "14      1   4.110   4.110   4.110    -1.0      14\n",
       "15      2   6.165   6.165   6.165     1.0      15\n",
       "16      1   1.515   1.515   0.000     0.0      16\n",
       "17      2   1.515   4.545   0.000     1.0      17"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Add interstitial at pos = [1.515, 1.515, 0.000] without defining atype, charge\n",
    "d_system = am.defect.interstitial(system, pos=[1.515, 1.515, 0.0])\n",
    "\n",
    "# Add second interstitial at pos = [1.515, 4.545, 0.000] with defining atype, charge\n",
    "d_system = am.defect.interstitial(d_system, pos=[1.515, 4.545, 0.0], atype=2, charge=1)\n",
    "\n",
    "# Print system information\n",
    "print(d_system.box)\n",
    "print('natoms =', d_system.natoms)\n",
    "print('natypes =', d_system.natypes)\n",
    "d_system.atoms_df()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. atomman.defect.substitutional()<a id='section4'></a>\n",
    "\n",
    "Generates a new system by adding a substitutional point defect.\n",
    "\n",
    "1. Moves the indicated atom to the end of the list and changes its atype to the value given.\n",
    "2. Adds per-atom property old_id if it doesn't exist corresponding to the atom ids in the original system.\n",
    "3. Sets any of the moved atom's per-atom properties to values given as kwargs.  Any undefined properties are left unchanged.\n",
    "    \n",
    "Parameters\n",
    "\n",
    "- **system** (*atomman.System*) The base System to add the defect to.\n",
    "- **pos** (*array-like object, optional*) Position of the atom being modified.  Either pos or ptd_id must be given.\n",
    "- **ptd_id** (*int, optional*) Id of the atom to be modified.  Either pos or ptd_id must be given.\n",
    "- **atype** (*int, optional*) Integer atomic type to change the identified atom to.  Must be different than the atom's current id.  Default value is 1.\n",
    "- **scale** (*bool, optional*) Indicates if pos is Cartesian (False) or box-relative (True).  Default value is False.\n",
    "- **atol** (*float, optional*) Absolute tolerance for position-based searching. Default value is 1e-3 angstroms.\n",
    "- **\\*\\*kwargs** (*any, optional*) Keyword arguments corresponding to per-atom property values for the modified atom.  By default, all properties (except atype) are left unchanged.\n",
    "    \n",
    "Returns\n",
    "\n",
    "- (*atomman.System*) A new system with the substitutional added."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "avect =  [ 8.220,  0.000,  0.000]\n",
      "bvect =  [ 0.000,  8.220,  0.000]\n",
      "cvect =  [ 0.000,  0.000,  8.220]\n",
      "origin = [ 0.000,  0.000,  0.000]\n",
      "natoms = 16\n",
      "natypes = 3\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>atype</th>\n",
       "      <th>pos[0]</th>\n",
       "      <th>pos[1]</th>\n",
       "      <th>pos[2]</th>\n",
       "      <th>charge</th>\n",
       "      <th>old_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>3</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>1.0</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    atype  pos[0]  pos[1]  pos[2]  charge  old_id\n",
       "0       1   0.000   0.000   0.000    -1.0       0\n",
       "1       1   4.110   0.000   0.000    -1.0       2\n",
       "2       2   6.165   2.055   2.055     1.0       3\n",
       "3       1   0.000   4.110   0.000    -1.0       4\n",
       "4       2   2.055   6.165   2.055     1.0       5\n",
       "5       1   4.110   4.110   0.000    -1.0       6\n",
       "6       2   6.165   6.165   2.055     1.0       7\n",
       "7       1   0.000   0.000   4.110    -1.0       8\n",
       "8       2   2.055   2.055   6.165     1.0       9\n",
       "9       1   4.110   0.000   4.110    -1.0      10\n",
       "10      2   6.165   2.055   6.165     1.0      11\n",
       "11      2   2.055   6.165   6.165     1.0      13\n",
       "12      1   4.110   4.110   4.110    -1.0      14\n",
       "13      2   6.165   6.165   6.165     1.0      15\n",
       "14      3   2.055   2.055   2.055     1.0       1\n",
       "15      2   0.000   4.110   4.110     1.0      12"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Make atom 1 a substitutional without changing charge\n",
    "d_system = am.defect.substitutional(system, ptd_id=1, atype=3)\n",
    "\n",
    "# Add second substitutional at pos = [0.00, 4.11, 4.11] and change charge\n",
    "d_system = am.defect.substitutional(d_system, pos=[0.00, 4.11, 4.11], atype=2, charge=1)\n",
    "\n",
    "# Print system information\n",
    "print(d_system.box)\n",
    "print('natoms =', d_system.natoms)\n",
    "print('natypes =', d_system.natypes)\n",
    "d_system.atoms_df()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5. atomman.defect.dumbbell()<a id='section5'></a>\n",
    "\n",
    "Generates a new system by adding a dumbbell interstitial point defect.\n",
    "\n",
    "1. Copies the indicated atom and moves both the original and copy to the end of the Atoms list.\n",
    "2. Displaces the dumbbell atoms position's by +-db_vect.\n",
    "3. Adds per-atom property old_id if it doesn't exist corresponding to the atom ids in the original system.\n",
    "4. Sets any of the new atom's per-atom properties to values given as kwargs.  Any undefined properties are left unchanged.\n",
    "    \n",
    "Parameters\n",
    "\n",
    "- **system** (*atomman.System*) The base System to add the defect to.\n",
    "- **pos** (*array-like object, optional*) Position of the atom being modified.  Either pos or ptd_id must be given.\n",
    "- **ptd_id** (*int, optional*) Id of the atom to be modified.  Either pos or ptd_id must be given.\n",
    "- **db_vect** (*array-like object*) Vector shift to apply to the atoms in the dumbbell.\n",
    "- **scale** (*bool, optional*) Indicates if pos and db_vect are Cartesian (False) or box-relative (True).  Default value is False.\n",
    "- **atol** (*float, optional*) Absolute tolerance for position-based searching. Default value is 1e-3 angstroms.\n",
    "- **\\*\\*kwargs** (*any, optional*) Keyword arguments corresponding to per-atom property values for the new atom in the dumbbell.  By default, all properties are left unchanged (i.e. same as atom that was copied).\n",
    "    \n",
    "Returns\n",
    "\n",
    "- (*atomman.System*) A new system with the dumbbell added."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "avect =  [ 8.220,  0.000,  0.000]\n",
      "bvect =  [ 0.000,  8.220,  0.000]\n",
      "cvect =  [ 0.000,  0.000,  8.220]\n",
      "origin = [ 0.000,  0.000,  0.000]\n",
      "natoms = 17\n",
      "natypes = 2\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>atype</th>\n",
       "      <th>pos[0]</th>\n",
       "      <th>pos[1]</th>\n",
       "      <th>pos[2]</th>\n",
       "      <th>charge</th>\n",
       "      <th>old_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "      <td>1.555</td>\n",
       "      <td>5.665</td>\n",
       "      <td>1.555</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>2</td>\n",
       "      <td>2.555</td>\n",
       "      <td>6.665</td>\n",
       "      <td>2.555</td>\n",
       "      <td>1.0</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    atype  pos[0]  pos[1]  pos[2]  charge  old_id\n",
       "0       1   0.000   0.000   0.000    -1.0       0\n",
       "1       2   2.055   2.055   2.055     1.0       1\n",
       "2       1   4.110   0.000   0.000    -1.0       2\n",
       "3       2   6.165   2.055   2.055     1.0       3\n",
       "4       1   0.000   4.110   0.000    -1.0       4\n",
       "5       1   4.110   4.110   0.000    -1.0       6\n",
       "6       2   6.165   6.165   2.055     1.0       7\n",
       "7       1   0.000   0.000   4.110    -1.0       8\n",
       "8       2   2.055   2.055   6.165     1.0       9\n",
       "9       1   4.110   0.000   4.110    -1.0      10\n",
       "10      2   6.165   2.055   6.165     1.0      11\n",
       "11      1   0.000   4.110   4.110    -1.0      12\n",
       "12      2   2.055   6.165   6.165     1.0      13\n",
       "13      1   4.110   4.110   4.110    -1.0      14\n",
       "14      2   6.165   6.165   6.165     1.0      15\n",
       "15      2   1.555   5.665   1.555     1.0       5\n",
       "16      2   2.555   6.665   2.555     1.0      16"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Turn atom 5 into a dumbbell\n",
    "d_system = am.defect.dumbbell(system, ptd_id=5, db_vect=[0.5, 0.5, 0.5])\n",
    "\n",
    "# Print system information\n",
    "print(d_system.box)\n",
    "print('natoms =', d_system.natoms)\n",
    "print('natypes =', d_system.natypes)\n",
    "d_system.atoms_df()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(d_system.atoms.pos[-1] - d_system.atoms.pos[-2]) / 2 -> [0.5 0.5 0.5]\n"
     ]
    }
   ],
   "source": [
    "# Show that dumbbell atoms are separated by 2 * db_vect\n",
    "print(\"(d_system.atoms.pos[-1] - d_system.atoms.pos[-2]) / 2 ->\", (d_system.atoms.pos[-1] - d_system.atoms.pos[-2]) / 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6. atomman.defect.point()<a id='section6'></a>\n",
    "\n",
    "Generates a new System where a point defect has been inserted.  Provides a common interface for the vacancy(), interstitial(), substitutional() and dumbbell() functions.\n",
    "    \n",
    "Parameters\n",
    "\n",
    "- **system** (*atomman.System*) The base System to add the defect to.\n",
    "- **ptd_type** (*str, optional*) Key indicating which type of defect to add. Default value is 'v':\n",
    "    - 'v' : vacancy.\n",
    "    - 'i' : positional interstitial.\n",
    "    - 's' : substitutional.\n",
    "    - 'db' : dumbbell interstitial.\n",
    "- **pos** (*array-like object, optional*) Position for adding the defect atom (all styles).\n",
    "- **ptd_id** (*int, optional*) Atom id where defect is added.  Alternative to using pos ('v', 's', 'db' styles).\n",
    "- **db_vect** (*array-like object, optional*) Vector associated with the dumbbell interstitial ('db' style).\n",
    "- **scale** (*bool, optional*) Indicates if pos and db_vect are Cartesian (False) or box-relative (True). Default value is False.\n",
    "- **atol** (*float, optional*) Absolute tolerance for position-based searching. Default value is 1e-3 angstroms.\n",
    "- **\\*\\*kwargs** (*any, optional*) Keyword arguments corresponding to per-atom property values for the new/modified atom ('i', 's', 'db' styles).\n",
    "    \n",
    "Raises\n",
    "\n",
    "- (*AssertionError*) If parameters are given for styles that don't allow them.\n",
    "- (*ValueError*) If an invalid ptd_type is given.\n",
    "    \n",
    "Returns\n",
    "\n",
    "- (*atomman.System*) A new system containing the defect."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "avect =  [ 8.220,  0.000,  0.000]\n",
      "bvect =  [ 0.000,  8.220,  0.000]\n",
      "cvect =  [ 0.000,  0.000,  8.220]\n",
      "origin = [ 0.000,  0.000,  0.000]\n",
      "natoms = 17\n",
      "natypes = 3\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>atype</th>\n",
       "      <th>pos[0]</th>\n",
       "      <th>pos[1]</th>\n",
       "      <th>pos[2]</th>\n",
       "      <th>charge</th>\n",
       "      <th>old_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>2</td>\n",
       "      <td>2.055</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>1</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>4.110</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>2</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.0</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>3</td>\n",
       "      <td>5.565</td>\n",
       "      <td>6.165</td>\n",
       "      <td>1.455</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>3</td>\n",
       "      <td>6.765</td>\n",
       "      <td>6.165</td>\n",
       "      <td>2.655</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    atype  pos[0]  pos[1]  pos[2]  charge  old_id\n",
       "0       1   0.000   0.000   0.000    -1.0       0\n",
       "1       2   2.055   2.055   2.055     1.0       1\n",
       "2       1   4.110   0.000   0.000    -1.0       2\n",
       "3       2   6.165   2.055   2.055     1.0       3\n",
       "4       1   0.000   4.110   0.000    -1.0       4\n",
       "5       2   2.055   6.165   2.055     1.0       5\n",
       "6       1   4.110   4.110   0.000    -1.0       6\n",
       "7       1   0.000   0.000   4.110    -1.0       8\n",
       "8       2   2.055   2.055   6.165     1.0       9\n",
       "9       1   4.110   0.000   4.110    -1.0      10\n",
       "10      2   6.165   2.055   6.165     1.0      11\n",
       "11      1   0.000   4.110   4.110    -1.0      12\n",
       "12      2   2.055   6.165   6.165     1.0      13\n",
       "13      1   4.110   4.110   4.110    -1.0      14\n",
       "14      2   6.165   6.165   6.165     1.0      15\n",
       "15      3   5.565   6.165   1.455    -0.5       7\n",
       "16      3   6.765   6.165   2.655    -0.5      16"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Use point() to make atom 7 a dumbbell of two atoms of atype 3\n",
    "\n",
    "# ptd_type 's' changes atom 7 and moves to last atom\n",
    "d_system = am.defect.point(system, 's', ptd_id=7, atype=3, charge=-0.5)\n",
    "\n",
    "# ptd_type 'db' turns last atom into dumbbell, copying per-atom properties\n",
    "d_system = am.defect.point(d_system, 'db', ptd_id=-1, db_vect=[0.6, 0.0, 0.6])\n",
    "\n",
    "# Print system information\n",
    "print(d_system.box)\n",
    "print('natoms =', d_system.natoms)\n",
    "print('natypes =', d_system.natypes)\n",
    "d_system.atoms_df()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "   "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
